package com.linln.modules.member.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.linln.common.data.PageSort;
import com.linln.modules.member.domain.Membernotice;
import com.linln.modules.member.repository.MembernoticeRepository;
import com.linln.modules.member.service.MembernoticeService;

/**
 * @author hct
 * @date 2019/10/11
 */
@Service
public class MembernoticeServiceImpl implements MembernoticeService {

    @Autowired
    private MembernoticeRepository membernoticeRepository;

    /**
     * 根据ID查询数据
     * @param id 主键ID
     */
    @Override
    @Transactional
    public Membernotice getById(Long id) {
        return membernoticeRepository.findById(id).orElse(null);
    }

    /**
     * 获取分页列表数据
     * @param example 查询实例
     * @return 返回分页数据
     */
    @Override
    public Page<Membernotice> getPageList(Example<Membernotice> example) {
        // 创建分页对象
        PageRequest page = PageSort.pageRequest();
        return membernoticeRepository.findAll(example, page);
    }

    /**
     * 保存数据
     * @param membernotice 实体对象
     */
    @Override
    public Membernotice save(Membernotice membernotice) {
        return membernoticeRepository.save(membernotice);
    }

    /**
     * 状态(启用，冻结，删除)/批量状态处理
     */
    @Override
    @Transactional
    public Boolean updateStatus(Integer status, List<Long> idList) {
        return membernoticeRepository.updateNoticeStatusByIds(status, idList) > 0;
    }
    @Override
    @Transactional
    public Boolean updateStatus(Integer status, Long id) {
        return membernoticeRepository.updateNoticeStatusById(status, id) > 0;
    }
    @Override    
    public Boolean updateIsread(Long id) {
    	return membernoticeRepository.updateIsreadById(id)>0;
    }

    
    @Override 
    public Boolean updateIsread(Integer type,Long typeId) {
    	return membernoticeRepository.updateIsreadById(type,typeId)>0;

    }

    
    @Override
    public Long getUnreadCount(Example<Membernotice> example) {
    	return membernoticeRepository.count( example);
    }
}